package cn.kduck.assembler.security;

import cn.kduck.assembler.security.authentication.PhoneNumAuthenticationToken;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent;
import org.springframework.stereotype.Component;

@Component
public class LoginAuthenticationAuditListener implements ApplicationListener<InteractiveAuthenticationSuccessEvent> {

    @Override
    public void onApplicationEvent(InteractiveAuthenticationSuccessEvent event) {
        Object source = event.getSource();
        Class<?> tokenClass = source.getClass();
        String loginType = "";
        if(UsernamePasswordAuthenticationToken.class.isAssignableFrom(tokenClass)){
            loginType = "帐号登录";
        }else if(PhoneNumAuthenticationToken.class.isAssignableFrom(tokenClass)){
            loginType = "手机号登录";
        }
        System.out.println(loginType + "-=-=-=-=-=->" + source);
    }
}
